/**
 * 
 */
package com.tocea.formation.books;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.tocea.formation.connection.ConnectionManager;

/**
 * @author AKWilson
 *
 */
public class BookDAOTest {

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		ConnectionManager.getConnectionManager();
	}

	/**
	 * Test method for {@link com.tocea.formation.books.BookDAO#save()}.
	 */
	@Test
	public final void testAdd() {
		Integer result = BookDAO.add(new BookImpl(1, "tested", "tested", 5));
		
		assertEquals(result.toString(), Integer.toString(1) );
	}
	
	/**
	 * Test method for {@link com.tocea.formation.books.BookDAO#save()}.
	 */
	@Test
	public final void testUpdate() {
		BookDAO.update(new BookImpl(1, "Updated", "Updated", 5));
		IBook book = BookDAO.get(1);
		System.out.println(book.getAuthor());
		assertEquals(book.getAuthor(), "Updated");
	}

	/**
	 * Test method for {@link com.tocea.formation.books.BookDAO#get(java.lang.Integer)}.
	 */
	@Test
	public final void testGet() {
		IBook book = BookDAO.get(2);
		assertEquals(book.getAuthor(), "unknown");
	}

	/**
	 * Test method for {@link com.tocea.formation.books.BookDAO#getBookByRent(java.lang.Integer)}.
	 */
	@Test
	public final void testGetBookByRent() {
		IBook book = BookDAO.getBookByRent(3);
		assertEquals(book.getId().toString(), Integer.toString(1));
	}

}
